package com.lzj.demo.design.prototype;

import java.util.*;
/**
 * 题目混排工具包
 * */
public class TopicRandomUtil {
    /**
     * @param option 题目
     * @param key 答案
     * @return Topic 混排后（A=c B=d C=a D=b）
     * */
    public static Topic random(Map<String,String> option, String key){
        Set<String> keySet = option.keySet();
        List<String> keyList = new ArrayList<>(keySet);
        Collections.shuffle(keyList);
        Map<String,String> optionNew = new HashMap<>();
        int idx = 0;
        String keyNew = "";
        for (String next:keySet) {
            String randomKey = keyList.get(idx++);
            if(key.equals(next)){
                keyNew = randomKey;
            }
            optionNew.put(randomKey,option.get(next));
        }
        return new Topic(optionNew,keyNew);
    }
}
